package com.example.movie_control;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;

public class TicketOrder {
    private String orderId;
    private String scheduleId;
    private String userId; // 购票用户ID
    private String seatsInfo; // 座位信息（格式："0,1;2,3"）
    private double totalPrice;
    private LocalDateTime createTime;

    // 构造器修改：存储座位信息字符串（而非int[]，避免解析问题）
    public TicketOrder(String scheduleId, String userId, String seatsInfo, double totalPrice) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
        String timePart = LocalDateTime.now().format(formatter);
        String randomPart = String.format("%03d", new Random().nextInt(1000));
        this.orderId = userId + "_" + timePart + "_" + randomPart;
        this.scheduleId = scheduleId;
        this.userId = userId;
        this.seatsInfo = seatsInfo;
        this.totalPrice = totalPrice;
        this.createTime = LocalDateTime.now();
    }

    // 修复：原方法递归调用问题，返回真实座位信息
    public String getSeatsInfo() { return seatsInfo; }

    // Getter & Setter（略，保持原有）
    public String getOrderId() { return orderId; }
    public String getScheduleId() { return scheduleId; }
    public LocalDateTime getCreateTime() { return createTime; }
    public double getTotalPrice() { return totalPrice; }
}